package com.tuzhh.htmlrtspplayer.bean;

import com.tuzhh.htmlrtspplayer.handler.ControlHandler;
import com.tuzhh.htmlrtspplayer.handler.DataHandler;
import com.tuzhh.htmlrtspplayer.interceptor.DataHandshakeInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
public class WebSocketConfig implements WebSocketConfigurer {
    public static final String PROXY_PROTOCOL = "WSP";
    public static final String PROXY_VERSION = "1.1";
    public static final String CMD_INIT = "INIT";
    public static final String CMD_JOIN = "JOIN";
    public static final String CMD_WRAP = "WRAP";

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // dataChannel
        registry.addHandler(new DataHandler(), "/ws/data")
                .setAllowedOrigins("*")
                .addInterceptors(new DataHandshakeInterceptor());

        // controlChannel
        registry.addHandler(new ControlHandler(), "/ws/control")
                .setAllowedOrigins("*")
                .addInterceptors(new DataHandshakeInterceptor());
    }
}
